/**
 * 操作
 */
function caozuo(){

}
/**
 * 添加
 */
function add(id){
    let payStandardCode = $(".payStandardCode").val();
    let nameOfSalary = $(".nameOfSalary").val();
    let developPeople = $(".developPeople").val();
    let registrant = $(".registrant").val();
    let regularWage = $(".regularWage").val();
    let performanceBonus = $(".performanceBonus").val();
    let transportation = $(".transportation").val();
    let phoneAllowance = $(".phoneAllowance").val();
    let mealSubsidy = $(".mealSubsidy").val();
    let housingAllowance = $(".housingAllowance").val();
    let travelAllowance = $(".travelAllowance").val();
    let overtimeAllowance = $(".overtimeAllowance").val();

    if (nameOfSalary == 0){
        alert("请选择薪酬标准名称")

        return;
    }
    if(payStandardCode==null||payStandardCode==""){
        alert("薪酬标准编号不能为空")
        return;
    }
    if(nameOfSalary==null||nameOfSalary==""){
        alert("薪酬标准名称不能为空")
        return;
    }
    if(developPeople==null||developPeople==""){
        alert("制定人不能为空")
        return;
    }
    if(registrant==null||registrant==""){
        alert("登记人不能为空")
        return;
    }
    if(regularWage==null||regularWage==""){
        alert("基本工资不能为空")

        return;
    }
    if(performanceBonus==null||performanceBonus==""){
        alert("绩效奖金不能为空")

        return;
    }
    if(transportation==null||transportation==""){
        alert("交通补助不能为空")

        return;
    }
    if(phoneAllowance==null||phoneAllowance==""){
        alert("通讯补助不能为空")

        return;
    }
    if(mealSubsidy==null||mealSubsidy==""){
        alert("餐补不能为空")
        return;
    }
    if(housingAllowance==null||housingAllowance==""){
        alert("住房补助不能为空")
        return;
    }
    if(travelAllowance==null||travelAllowance==""){
        alert("出差补助不能为空")
        return;
    }
    if(overtimeAllowance==null||overtimeAllowance==""){
        alert("加班补助不能为空")
        return;
    }
    if(id==2) {
        let json = {
            "payStandardCode": payStandardCode,
            "nameOfSalary": nameOfSalary,
            "developPeople": developPeople,
            "registrant": registrant,
            "regularWage": regularWage,
            "performanceBonus": performanceBonus,
            "transportation": transportation,
            "phoneAllowance": phoneAllowance,
            "mealSubsidy": mealSubsidy,
            "housingAllowance": housingAllowance,
            "travelAllowance": travelAllowance,
            "overtimeAllowance": overtimeAllowance,
            "checkState":"审核中"
        }


        $.getJSON("/sal/save", json, function (data) {
            if (data == true) {
                alert("添加成功");
                location.href = "sel"
            } else {
                alert("添加失败");
            }
        })
    }

    if(id==1) {
        let jsonA = {
            "payStandardCode": payStandardCode,
            "nameOfSalary": nameOfSalary,
            "developPeople": developPeople,
            "registrant": registrant,
            "regularWage": regularWage,
            "performanceBonus": performanceBonus,
            "transportation": transportation,
            "phoneAllowance": phoneAllowance,
            "mealSubsidy": mealSubsidy,
            "housingAllowance": housingAllowance,
            "travelAllowance": travelAllowance,
            "overtimeAllowance": overtimeAllowance,
            "checkState":"起草"
        }


        $.getJSON("/sal/save", jsonA, function (data) {
            if (data == true) {
                alert("保存成功");
                location.href = "sel"
            } else {
                alert("保存失败");
            }
        })
    }
}

/**
 * 查询名字唯一性
 */
function selname() {
    let nameOfSalary = $(".nameOfSalary").val();
    let jsonA={
        nameOfSalary:nameOfSalary
    }
    $.getJSON("/sal/selname",jsonA,function (data){
        if(data==true){

            alert("该职业已存在！");
            $(".nameOfSalary").val("");
            return true;
        }
            return false;
    })
}

/**
 * 修改
 */
function update(num){
    let txt = $(".txt").val();
    let id = $(".id").val();
    let payStandardCode = $(".payStandardCode").val();
    let nameOfSalary = $(".nameOfSalary").val();
    let developPeople = $(".developPeople").val();
    let registrant = $(".registrant").val();
    let regularWage = $(".regularWage").val();
    let performanceBonus = $(".performanceBonus").val();
    let transportation = $(".transportation").val();
    let phoneAllowance = $(".phoneAllowance").val();
    let mealSubsidy = $(".mealSubsidy").val();
    let housingAllowance = $(".housingAllowance").val();
    let travelAllowance = $(".travelAllowance").val();
    let overtimeAllowance = $(".overtimeAllowance").val();
    if(txt == ""){
        alert("变更原因不能为空");
        return;
    }
    if (nameOfSalary == 0){
        alert("薪酬标准名称不能为空")
        return;
    }
    if(payStandardCode==null||payStandardCode==""){
        alert("薪酬标准编号不能为空")
        return;
    }
    if(nameOfSalary==null||nameOfSalary==""){
        alert("薪酬标准名称不能为空")
        return;
    }
    if(developPeople==null||developPeople==""){
        alert("制定人不能为空")
        return;
    }
    if(registrant==null||registrant==""){
        alert("登记人不能为空")
        return;
    }
    if(regularWage==null||regularWage==""){
        alert("基本工资不能为空")

        return;
    }
    if(performanceBonus==null||performanceBonus==""){
        alert("绩效奖金不能为空")

        return;
    }
    if(transportation==null||transportation==""){
        alert("交通补助不能为空")

        return;
    }
    if(phoneAllowance==null||phoneAllowance==""){
        alert("通讯补助不能为空")

        return;
    }
    if(mealSubsidy==null||mealSubsidy==""){
        alert("餐补不能为空")
        return;
    }
    if(housingAllowance==null||housingAllowance==""){
        alert("住房补助不能为空")
        return;
    }
    if(travelAllowance==null||travelAllowance==""){
        alert("出差补助不能为空")
        return;
    }
    if(overtimeAllowance==null||overtimeAllowance==""){
        alert("加班补助不能为空")
        return;
    }
    if(num == 2) {
        let json = {
            "id": id,
            "payStandardCode": payStandardCode,
            "nameOfSalary": nameOfSalary,
            "developPeople": developPeople,
            "registrant": registrant,
            "regularWage": regularWage,
            "performanceBonus": performanceBonus,
            "transportation": transportation,
            "phoneAllowance": phoneAllowance,
            "mealSubsidy": mealSubsidy,
            "housingAllowance": housingAllowance,
            "travelAllowance": travelAllowance,
            "overtimeAllowance": overtimeAllowance,
            "txt":txt,
            "checkState": "审核中"
        }
        console.log(json)
        $.getJSON("/sal/updsave", json, function (data) {
            if (data == true) {
                alert("操作成功");
                location.href = "/sal/sel"
            } else {
                alert("操作失败");
            }
        })
    }
    if(num==1){
        let json = {
            "id": id,
            "payStandardCode": payStandardCode,
            "nameOfSalary": nameOfSalary,
            "developPeople": developPeople,
            "registrant": registrant,
            "regularWage": regularWage,
            "performanceBonus": performanceBonus,
            "transportation": transportation,
            "phoneAllowance": phoneAllowance,
            "mealSubsidy": mealSubsidy,
            "housingAllowance": housingAllowance,
            "travelAllowance": travelAllowance,
            "overtimeAllowance": overtimeAllowance,
            "txt":txt,
            "checkState": "起草"
        }
        console.log(json)
        $.getJSON("/sal/updsave", json, function (data) {
            if (data == true) {
                alert("保存成功");
                location.href = "/sal/sel"
            } else {
                alert("保存失败");
            }
        })
    }
}

function sum(){
    let regularWage = Number($(".regularWage").val());
    let performanceBonus = Number($(".performanceBonus").val());
    let transportation = Number($(".transportation").val());
    let phoneAllowance = Number($(".phoneAllowance").val());
    let mealSubsidy = Number($(".mealSubsidy").val());
    let housingAllowance = Number($(".housingAllowance").val());
    let travelAllowance = Number($(".travelAllowance").val());
    let overtimeAllowance = Number($(".overtimeAllowance").val());
    let parroll = regularWage+performanceBonus+transportation+phoneAllowance+mealSubsidy+housingAllowance+travelAllowance+overtimeAllowance;
    $(".sum").html("<input type=\"text\" name=\"parroll\" class=\"parroll layui-input reName1\" value='"+parroll+"' readonly >");
}
function state(){
    let state= $(".state").val();
    if(state=="审核通过"){
        $(".caozuo").html(
            "    <input type=\"button\" onclick=\"update(2)\" class=\"layui-btn layui-btn-normal\" value=\"提交\">\n" +
            "    <input type=\"button\" onclick=\"location.href='/sal/sel'\" class=\"layui-btn layui-btn-normal\" value=\"返回\">")
    }else{
        $(".caozuo").html("    <input type=\"button\" onclick=\"update(1)\" class=\"layui-btn layui-btn-normal\" value=\"保存\">\n" +
            "    <input type=\"button\" onclick=\"update(2)\" class=\"layui-btn layui-btn-normal\" value=\"提交\">\n" +
            "    <input type=\"button\" onclick=\"location.href='/sal/sel'\" class=\"layui-btn layui-btn-normal\" value=\"返回\">")
    }

    if($(".state").val()=="审核通过"){
        $(".t").html("<textarea class='txt' width='200px' style='width: 97%;height: 250px'></textarea>")
    }

}
function agree(num){
    let id = $(".id").val();
    let rank = "审核通过";
    if(num==2){
        rank = "驳回";
    }
    let json={
        id:id,
        rank:rank
    }

    $.getJSON("/sal/updrank",json,function(data){
        if(data==true){
            alert("操作成功");
            location.href="/sal/sel"
        }else{
            alert("操作失败");
        }
    })

}